package com.wyx.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;


@Data
@NoArgsConstructor
@AllArgsConstructor
public class CommonResult<T> {


    private Integer code;
    private String message;
    private T data;


    public static CommonResult Success(Object data){
        return new CommonResult(200,"success",data);
    }

    public static CommonResult Error(){
        HashMap<String, String> map = new HashMap<>();
        map.put("warning",String.valueOf("请求出错，请联系管理员"));
        return new CommonResult(444,"error",map);
    }

    public static CommonResult isNull(){
        HashMap<String, String> map = new HashMap<>();
        map.put("warning",String.valueOf("请求数据为空，请联系管理员"));
        return new CommonResult(404,"error",map);
    }

    public static CommonResult perNoAll(){
        HashMap<String, String> map = new HashMap<>();
        map.put("message",String.valueOf("权限不允许，请联系管理员"));
        return new CommonResult(401,"warning",map);
    }

    public static CommonResult ErrorMethod(){
        HashMap<String, String> map = new HashMap<>();
        map.put("message",String.valueOf("请求方法错误，请查看请求方法"));
        return new CommonResult(403,"warning",map);
    }

    public static CommonResult Exception(){
        HashMap<String, String> map = new HashMap<>();
        map.put("message",String.valueOf("服务器内部错误，请联系管理员"));
        return new CommonResult(500,"error",map);
    }

    public static CommonResult MyMessage (String message){
        HashMap<String, String> map = new HashMap<>();
        map.put("message",message);
        return new CommonResult(911,"warning",map);
    }

}